//
//  MineTongJiViewController.m
//  rrqs
//
//  Created by 杜文杰 on 2018/8/31.
//

#import "MineTongJiViewController.h"
#import "SGPagingView.h"
#import "WJSendMessageCollectionViewCell.h"
#import "ChooseServerTypeCollectionReusableView.h"
#import "WJFooterCollectionReusableView.h"

@interface MineTongJiViewController ()<SGPageTitleViewDelegate, SGPageContentViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) UIButton *makesureBtn;
@property (nonatomic, strong) UICollectionView *shopingCollectionView;
@property (nonatomic, strong) NSMutableArray *datamuArray;
@end

@implementation MineTongJiViewController

- (void)queryData {
    AFHTTPRequestOperationManager* mgr = [AFHTTPRequestOperationManager manager];
    NSDictionary* arg = @{@"ince":@"get_one_qishi_total",@"time":@"20180910",@"emp_id":@"139",@"token":@"ik0vRd"};
    [mgr POST:@"http://xmpc.zadtek.com/index.php?/mobile/Qs/index" parameters:arg success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        [WMHelper outPutJsonString:responseObject];
        NSInteger flag = [[responseObject objectForKey:@"status"]integerValue];
        NSDictionary* dict = [responseObject objectForKey:@"data"];
        
    } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
        [self alertHUD:@"网络异常"];
    }];
}
- (void)buttonAction
{
    NSLog(@"确认按钮");
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的统计";
    self.view.backgroundColor = getColor(@"F8F8F8");
    [self.view addSubview:self.pageTitleView];
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 25)];
    UIButton *button = [[UIButton alloc] initWithFrame:contentView.bounds];
    [button.titleLabel sizeToFit];
    self.makesureBtn = button;
    [button setTitle:@"排行榜" forState:UIControlStateNormal];
    [button setTitleColor:getColor(whiteColor) forState:UIControlStateNormal];
    button.titleLabel.font = DEF_FontSize_14;
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button];
    UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:contentView];
    self.navigationItem.rightBarButtonItems = @[button2];
    
    [self.view addSubview:self.shopingCollectionView];
    __weak typeof(self)weakself = self;
    
    [self.shopingCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.pageTitleView.mas_bottom).offset(15 / HEIGHT_6S_SCALE);
        make.left.right.equalTo(weakself.view);
        make.height.mas_equalTo(SCREEN_HEIGHT - SafeAreaTopHeight - SafeAreaBottomHeight - 44);
    }];
    [self queryData];
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    NSLog(@"你说喜欢有用吗%ld",(long)selectedIndex);
}

- (SGPageTitleView *)pageTitleView {
    if (!_pageTitleView) {
        NSArray *titleArr = @[@"昨天", @"今天", @"本月",@"上月"];
        SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
        configure.titleSelectedColor = getColor(@"F7B12E");
        configure.indicatorColor = getColor(@"F7B12E");
        configure.indicatorAdditionalWidth = 40;
        
        /// pageTitleView
        _pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44) delegate:self titleNames:titleArr configure:configure];
        _pageTitleView.backgroundColor = getColor(@"F8F8F8");
        
    }
    return _pageTitleView;
}

#pragma mark - UICollectionViewDelegate and UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 3;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 1) {
        return 4;
    }
    return 2;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WJSendMessageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([WJSendMessageCollectionViewCell class]) forIndexPath:indexPath];
    cell.backgroundColor = getColor(whiteColor);
//    cell.dataDic = self.datamuArray[indexPath.row];
    if (indexPath.section == 1) {
        if (indexPath.row == 0 || indexPath.row == 1) {
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1, cell.contentView.frame.size.width, 2)];
            lineView.backgroundColor = getColor(dividerColor);
            [cell.contentView addSubview:lineView];
        }
        if (indexPath.row == 0 || indexPath.row == 2) {
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(cell.contentView.frame.size.width - 1, 5, 2, cell.contentView.frame.size.height - 10)];
            lineView.backgroundColor = getColor(dividerColor);
            [cell.contentView addSubview:lineView];
        }
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(cell.contentView.frame.size.width - 1, 5, 2, cell.contentView.frame.size.height - 10)];
            lineView.backgroundColor = getColor(dividerColor);
            [cell.contentView addSubview:lineView];
        }
    }
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    ChooseServerTypeViewController *VC = [[ChooseServerTypeViewController alloc]init];
//    VC.hidesBottomBarWhenPushed = YES;
//    VC.dataDic = self.datamuArray[indexPath.row];
//    [self.navigationController pushViewController:VC animated:NO];
    
}
// 设置头尾部内容(多数情况可以不用)
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableView =nil;
    
    if (kind == UICollectionElementKindSectionHeader) {
        //定制头部视图的内容
        ChooseServerTypeCollectionReusableView *headerV = (ChooseServerTypeCollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
        reusableView = headerV;
    }
    if (kind == UICollectionElementKindSectionFooter) {
        //定制头部视图的内容
        WJFooterCollectionReusableView *FooterV = (WJFooterCollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
        if (indexPath.section == 2) {
            UILabel *lab = [[UILabel alloc]init];
            lab.textColor = getColor(blackColor);
            lab.backgroundColor = [UIColor clearColor];
            lab.font = DEF_FontSize_12;
            lab.text = @"统计截止昨天23:59前数据，请于次日9:00后查看";
            [FooterV addSubview:lab];
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(FooterV.mas_left).offset(5 / WIDTH_6S_SCALE);
                make.right.equalTo(FooterV);
                make.width.height.mas_equalTo(FooterV);
            }];
        }
        reusableView = FooterV;
    }
    
    return reusableView;
}
- (UICollectionView *)shopingCollectionView
{
    if (!_shopingCollectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH / 2,90 / HEIGHT_6S_SCALE);
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.sectionInset = UIEdgeInsetsMake(0 / HEIGHT_6S_SCALE, 0, 0, 0);
        // 设置头部并给定大小(多数情况可以不用)
        [flowLayout setHeaderReferenceSize:CGSizeMake(SCREEN_HEIGHT,0 / HEIGHT_6S_SCALE)];
        [flowLayout setFooterReferenceSize:CGSizeMake(SCREEN_HEIGHT,20 / HEIGHT_6S_SCALE)];
        
        _shopingCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _shopingCollectionView.backgroundColor = [UIColor clearColor];
        _shopingCollectionView.bounces = YES;
        _shopingCollectionView.delegate = self;
        _shopingCollectionView.dataSource = self;
        _shopingCollectionView.showsVerticalScrollIndicator = NO;
        _shopingCollectionView.showsHorizontalScrollIndicator = NO;
        _shopingCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_shopingCollectionView registerClass:[WJSendMessageCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([WJSendMessageCollectionViewCell class])];
        // 注册头部视图
        [_shopingCollectionView registerClass:[ChooseServerTypeCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
        // 注册尾部视图
        [_shopingCollectionView registerClass:[WJFooterCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView"];
    }
    
    return _shopingCollectionView;
}
- (NSMutableArray *)datamuArray
{
    if (!_datamuArray) {
        _datamuArray = @[@{@"catico":@"WX20180719-a",@"catname":@"房产信息"},
                         @{@"catico":@"WX20180719-b",@"catname":@"招聘信息"},
                         @{@"catico":@"WX20180719-c",@"catname":@"二手市场"},
                         @{@"catico":@"WX20180719-d",@"catname":@"拼车顺风车"},
                         @{@"catico":@"WX20180719-e",@"catname":@"宠物"},
                         @{@"catico":@"WX20180719-f",@"catname":@"教育培训"},
                         @{@"catico":@"WX20180719-d",@"catname":@"劳务市场"},
                         @{@"catico":@"WX20180719-c",@"catname":@"装修建材"},
                         @{@"catico":@"WX20180719-b",@"catname":@"家政服务"},
                         @{@"catico":@"WX20180719-a",@"catname":@"thinking"}].mutableCopy;
    }
    return _datamuArray;
}
@end
